import XtxConfirm from './confirm.vue'
import { h, render } from 'vue'

const div = document.createElement('div')
div.setAttribute('class', 'xtx-confirm-container')
document.body.appendChild(div)

type props = {
  title?: String
  text: string
}
export default function confirm({ title, text }: props) {
  return new Promise((resolve, reject) => {
    const confirmCallback = () => {
      resolve(undefined)
      render(null, div)
    }
    const cancelCallback = () => {
      // reject()
      render(null, div)
    }

    const vNode = h(XtxConfirm, { title, text, confirmCallback, cancelCallback })
    render(vNode, div)
  })
}
